package 常用方法.转化.字符串转数组;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 姚东名
 * Date: 2024-06-20
 * Time: 11:58
 */
public class Test {
    public static void main(String[] args) {
        String s = "hello";
        //1. 字符串转数组
        char[] ch = s.toCharArray();//{'h', 'e', 'l', 'l', 'o'};
        for (int i = 0; i < ch.length; i++) {
            System.out.print(ch[i] + " ");
        }
        System.out.println();
        //2. 数组转字符串
        String s2 = new String(ch);
        System.out.println(s2);
    }
}

/*
执行结果：
h e l l o
hello
 */